<template>
  <div class="app-container">
    <el-form ref="form" :model="financialInstruments" label-width="80px" >
      <el-form-item label="债券代码">
        <el-col :span="11">
          <el-input v-model="financialInstruments.debentureCode" placeholder="债券代码" style="width: 80%;"/>
        </el-col>
        <el-col :span="11">
          <el-form-item label="起息日">
            <el-date-picker v-model="financialInstruments.dueDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 80%;">李四</el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="债券名称">
        <el-col :span="11">
          <el-input v-model="financialInstruments.debentureName" placeholder="债券名称" style="width: 80%;"/>
        </el-col>
        <el-col :span="11">
          <el-form-item label="到息日">
            <el-date-picker v-model="financialInstruments.valueDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 80%;">李四</el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="市场">
        <el-col :span="11">
          <el-input v-model="financialInstruments.market" placeholder="市场" style="width: 80%;"/>
        </el-col>
        <el-col :span="11">
          <el-form-item label="固定利率">
            <el-input v-model="financialInstruments.fixedInterestRate" placeholder="固定利率" style="width: 80%;"/>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="面值">
        <el-col :span="11">
          <el-input v-model="financialInstruments.parValue" placeholder="面值" style="width: 80%;"/>
        </el-col>
      </el-form-item>
      <el-form-item class="de-button">
        <el-button type="primary" @click="onSubmit()">保存</el-button>
        <el-button @click="onCancel()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import instrument from '@/api/instrument'
export default {
  data() {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      financialInstruments: {}
    }
  },
  created() {
    this.id = this.$route.params.id
    this.findOne(this.id)
    this.fetchData()
  },
  methods: {
    findOne(id) {
      instrument.find(id).then(response => {
        this.financialInstruments = response.data
        console.log(this.debenture)
      })
    },
    onSubmit() {
      instrument.save(this.financialInstruments).then(response => {
        this.onCancel()
      })
        .catch(error => { // 请求失败
          console.log(error)
        })
    },
    onCancel() {
      this.$router.push({ path: '/table/table' })
    }
  }
}
</script>

<style scoped>
.right-form{
  width: 300px;
}
.left-form{
  width: 300px;
}
.app-container{
  color: white;
  margin-left: 120px;
}
.de-button{
  margin-top: 60px;
  margin-left: 300px;
}
</style>
